package com.huwei.activemq.mq;

import com.huwei.activemq.entity.MsgEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 胡伟
 * @Date: 2021/1/14 15:00
 * @Description:
 */
@Component
public class Consumer1 {
    public static  long count = 0;

    @RabbitListener(queues = "huwei")
    @RabbitHandler
    public void getMsg(MsgEntity msg, Channel channel, Message message) throws IOException {
        System.out.println("huwei1->我消费了消息---------------->" + msg.toString() + "-----消费次数" + Consumer1.count++);
//        if(Consumer.count > 3){
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(),true);
//        }
//        channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
    }
}
